package com.lh.blogConsumer.controller.admin;

import com.lh.blogCommon.result.LhR;
import com.lh.blogConsumer.entity.Member;
import com.lh.blogConsumer.service.IMemberService;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

//创建时间 2021/3/16
//创建人 lh
//@Api(description = "用户管理")
//@CrossOrigin
@RestController
@RequestMapping("user")
public class LoginController {

    @Autowired
    IMemberService memberService;

//    @ApiOperation("登录")
    @PostMapping("login/{username}/{password}")
    public LhR login(@ApiParam(value = "手机号",required = true) @PathVariable String username,
                     @ApiParam(value = "密码",required = true) @PathVariable String password){
        Member member = new Member();
        member.setMobile(username);
        member.setPassword(password);
        String token=memberService.login(member);
        return LhR.ok().data("token",token).message("登录成功");
    }

//    @ApiOperation("验证登录")
    @GetMapping("verifyLogin/{token}")
    public LhR verifyLogin(@PathVariable("token") String token) throws Exception {
        try {
            Member member = memberService.info(token);
            return LhR.ok().data("member",member);
        } catch (Exception err) {
            throw new Exception("验证错误:" + err.getMessage());
        }
    }

    @PostMapping("logout")
    public LhR logout(){
        return LhR.ok();
    }

}
